<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${pageContext.request.contextPath}/themes/layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body> 

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>用户列表</legend>
</fieldset>
 
<table class="layui-table" id="userTable" lay-filter="demo"></table>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
               
<script src="${pageContext.request.contextPath}/js/jQuery.js"></script>
<script src="${pageContext.request.contextPath}/themes/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use('table', function(){
  var table = layui.table;
  
  table.render({
    elem: '#userTable'
    ,url:'/words/user/userList.do'
    ,method : 'get'
    ,page: true //开启分页
    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
    ,cols: [[
      {field:'userId', width: '15%', minWidth: 120, title: 'ID', sort: true, fixed: 'left'},
      {field:'userName', width: '15%', minWidth: 120, title: '姓名'},
      {field:'userPassword', width: '15%', minWidth: 120, title: '密码'},
      {field:'userNickName', title: '昵称', width: '20%', minWidth: 120},
      {field:'right', title: '操作', width:'10%',toolbar:"#barDemo"}
    ]]
  });
  
//监听工具条
  table.on('tool(demo)', function(obj){
    var d = obj.data;
    if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
    	  
    	  $.ajax({  
  	        type: "post",  
  	        url: "/words/user/deleteUser.do",
  	        data: {userId:d.userId},
  	        dataType:"JSON",
  	        success:function(t){  
  	            if(t.status == 1){  
  	            	
  	            	layer.close(index);
  	                alert('提交成功');
  	              window.location.reload();
  	  
  	            }else  
  	                alert('提交失败');  
  	        }
  	    });  
    	  
      });
    }
  });
});
</script>

</body>
</html>